<<<<<<< HEAD
from nicegui import ui
import plotly.graph_objects as go

# 初始化数据
data = {
    'x': [],
    'y': [],
    'z': []
}

# 创建一个空的 3D 散点图
fig = go.Figure(data=[go.Scatter3d(x=[], y=[], z=[], mode='markers', marker=dict(size=5))])

# 设置图表布局
fig.update_layout(
    title='三维散点图',
    scene=dict(
        xaxis=dict(title='X 轴'),
        yaxis=dict(title='Y 轴'),
        zaxis=dict(title='Z 轴')
    )
)

# 创建输入框和按钮
with ui.column():
    with ui.row():
        x_input = ui.number(label='X 值', value=0)
        y_input = ui.number(label='Y 值', value=0)
        z_input = ui.number(label='Z 值', value=0)
    with ui.row():
        add_button = ui.button('添加点')
        delete_button = ui.button('删除点')

# 创建 Plotly 图表，并设置尺寸
plot = ui.plotly(fig).classes('w-full h-120')  # 设置宽度为 100%，高度为 384px

# 定义添加点的函数
def add_point():
    x = x_input.value
    y = y_input.value
    z = z_input.value

    # 检查输入值是否有效
    if x is None or y is None or z is None:
        ui.notify('请输入有效的 X、Y、Z 值！', type='negative')
        return

    # 添加新点到数据中
    data['x'].append(x)
    data['y'].append(y)
    data['z'].append(z)

    # 更新图表
    fig.data[0].x = data['x']
    fig.data[0].y = data['y']
    fig.data[0].z = data['z']
    plot.update()

    # 清空输入框
    x_input.value = 0
    y_input.value = 0
    z_input.value = 0

    ui.notify(f'已添加点: ({x}, {y}, {z})', type='positive')

# 定义删除点的函数
def delete_point():
    if not data['x']:
        ui.notify('没有可删除的点！', type='warning')
        return

    # 删除最后一个点
    x = data['x'].pop()
    y = data['y'].pop()
    z = data['z'].pop()

    # 更新图表
    fig.data[0].x = data['x']
    fig.data[0].y = data['y']
    fig.data[0].z = data['z']
    plot.update()

    ui.notify(f'已删除点: ({x}, {y}, {z})', type='info')

# 绑定按钮点击事件
add_button.on_click(add_point)
delete_button.on_click(delete_point)

# 启动 NiceGUI 应用
=======
from nicegui import ui
import plotly.graph_objects as go

# 初始化数据
data = {
    'x': [],
    'y': [],
    'z': []
}

# 创建一个空的 3D 散点图
fig = go.Figure(data=[go.Scatter3d(x=[], y=[], z=[], mode='markers', marker=dict(size=5))])

# 设置图表布局
fig.update_layout(
    title='三维散点图',
    scene=dict(
        xaxis=dict(title='X 轴'),
        yaxis=dict(title='Y 轴'),
        zaxis=dict(title='Z 轴')
    )
)

# 创建输入框和按钮
with ui.column():
    with ui.row():
        x_input = ui.number(label='X 值', value=0)
        y_input = ui.number(label='Y 值', value=0)
        z_input = ui.number(label='Z 值', value=0)
    with ui.row():
        add_button = ui.button('添加点')
        delete_button = ui.button('删除点')

# 创建 Plotly 图表，并设置尺寸
plot = ui.plotly(fig).classes('w-full h-120')  # 设置宽度为 100%，高度为 384px

# 定义添加点的函数
def add_point():
    x = x_input.value
    y = y_input.value
    z = z_input.value

    # 检查输入值是否有效
    if x is None or y is None or z is None:
        ui.notify('请输入有效的 X、Y、Z 值！', type='negative')
        return

    # 添加新点到数据中
    data['x'].append(x)
    data['y'].append(y)
    data['z'].append(z)

    # 更新图表
    fig.data[0].x = data['x']
    fig.data[0].y = data['y']
    fig.data[0].z = data['z']
    plot.update()

    # 清空输入框
    x_input.value = 0
    y_input.value = 0
    z_input.value = 0

    ui.notify(f'已添加点: ({x}, {y}, {z})', type='positive')

# 定义删除点的函数
def delete_point():
    if not data['x']:
        ui.notify('没有可删除的点！', type='warning')
        return

    # 删除最后一个点
    x = data['x'].pop()
    y = data['y'].pop()
    z = data['z'].pop()

    # 更新图表
    fig.data[0].x = data['x']
    fig.data[0].y = data['y']
    fig.data[0].z = data['z']
    plot.update()

    ui.notify(f'已删除点: ({x}, {y}, {z})', type='info')

# 绑定按钮点击事件
add_button.on_click(add_point)
delete_button.on_click(delete_point)

# 启动 NiceGUI 应用
>>>>>>> 92e874dd43937b2ee12daa8e2d273d3df5b8964c
ui.run()